Fix `cargo test` with a dylib when run twice
authorAlex Crichton <alex@alexcrichton.com>
Wed, 23 Jul 2014 16:09:33 +0000 (09:09 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 23 Jul 2014 19:19:02 +0000 (12:19 -0700)
The filename of the test for a dylib wasn't being calcuated correctly, so when
freshness was copying data over it ended up copying the same file twice.

src/cargo/ops/cargo_rustc/context.rs
tests/test_cargo_test.rs

index 083c12becec13f97fa76901943374c4f78285b3a..9a113e41b5302a7003e7db117bc73e6f882cb81b 100644 (file)
@@ -175,20 +175,17 @@ impl<'a, 'b> Context<'a, 'b> {
         let stem = target.file_stem();
 
         let mut ret = Vec::new();
-        if target.is_dylib() {
-            let (prefix, suffix) = self.dylib(target.get_profile().is_plugin());
-            ret.push(format!("{}{}{}", prefix, stem, suffix));
-        }
-        if target.is_rlib() {
-            if target.get_profile().is_test() {
-                ret.push(format!("{}{}", stem, self.target_exe));
-            } else {
+        if target.is_bin() || target.get_profile().is_test() {
+            ret.push(format!("{}{}", stem, self.target_exe));
+        } else {
+            if target.is_dylib() {
+                let (prefix, suffix) = self.dylib(target.get_profile().is_plugin());
+                ret.push(format!("{}{}{}", prefix, stem, suffix));
+            }
+            if target.is_rlib() {
                 ret.push(format!("lib{}.rlib", stem));
             }
         }
-        if target.is_bin() {
-            ret.push(format!("{}{}", stem, self.target_exe));
-        }
         assert!(ret.len() > 0);
         return ret;
     }
index 1a0ff9c942cc889e4713919faf1a450250c63937..16eb46ddaeb832882847525b7856612b140fa419 100644 (file)
@@ -2,7 +2,7 @@ use std::path;
 use std::str;
 
 use support::{project, execs, basic_bin_manifest, basic_lib_manifest};
-use support::{COMPILING, cargo_dir, ResultTest};
+use support::{COMPILING, cargo_dir, ResultTest, FRESH};
 use hamcrest::{assert_that, existing_file};
 use cargo::util::process;
 
@@ -516,3 +516,46 @@ test!(bin_there_for_integration {
     assert!(output.contains("main_test ... ok"), "no main_test\n{}", output);
     assert!(output.contains("test_test ... ok"), "no test_test\n{}", output);
 })
+
+test!(test_dylib {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [[lib]]
+            name = "foo"
+            crate_type = ["dylib"]
+        "#)
+        .file("src/lib.rs", "
+            #[test]
+            fn foo() {}
+        ");
+
+    assert_that(p.cargo_process("cargo-test"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{compiling} foo v0.0.1 (file:{dir})
+
+running 1 test
+test foo ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
+                       ",
+                       compiling = COMPILING,
+                       dir = p.root().display()).as_slice()));
+    assert_that(p.process(cargo_dir().join("cargo-test")),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{fresh} foo v0.0.1 (file:{dir})
+
+running 1 test
+test foo ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
+                       ",
+                       fresh = FRESH,
+                       dir = p.root().display()).as_slice()));
+})